package com.ruoyi.web.controller.monitor;

import java.util.List;

import com.ruoyi.web.core.aspectj.CountResponseTime;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCostTime;
import com.ruoyi.system.service.ISysCostTimeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统响应时间统计记录（方便对响应时间长的进行优化）Controller
 * 
 * @author ruoyi
 * @date 2019-11-20
 */
@Controller
@RequestMapping("/monitor/time")
public class SysCostTimeController extends BaseController
{
    private String prefix = "monitor/time";

    @Autowired
    private ISysCostTimeService sysCostTimeService;

    @RequiresPermissions("monitor:time:view")
    @GetMapping()
    public String time(ModelMap modelMap)
    {
        modelMap.put("CONDITION_TIME", CountResponseTime.CONDITION_TIME);
        return prefix + "/time";
    }

    /**
     * 查询系统响应时间统计记录（方便对响应时间长的进行优化）列表
     */
    @RequiresPermissions("monitor:time:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysCostTime sysCostTime)
    {
        startPage();
        List<SysCostTime> list = sysCostTimeService.selectSysCostTimeList(sysCostTime);
        return getDataTable(list);
    }

    /**
     * 导出系统响应时间统计记录（方便对响应时间长的进行优化）列表
     */
    @RequiresPermissions("monitor:time:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysCostTime sysCostTime)
    {
        List<SysCostTime> list = sysCostTimeService.selectSysCostTimeList(sysCostTime);
        ExcelUtil<SysCostTime> util = new ExcelUtil<SysCostTime>(SysCostTime.class);
        return util.exportExcel(list, "time");
    }

    /**
     * 新增系统响应时间统计记录（方便对响应时间长的进行优化）
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存系统响应时间统计记录（方便对响应时间长的进行优化）
     */
    @RequiresPermissions("monitor:time:add")
    @Log(title = "系统响应时间统计记录（方便对响应时间长的进行优化）", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysCostTime sysCostTime)
    {
        return toAjax(sysCostTimeService.insertSysCostTime(sysCostTime));
    }

    /**
     * 修改系统响应时间统计记录（方便对响应时间长的进行优化）
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysCostTime sysCostTime = sysCostTimeService.selectSysCostTimeById(id);
        mmap.put("sysCostTime", sysCostTime);
        return prefix + "/edit";
    }

    /**
     * 修改保存系统响应时间统计记录（方便对响应时间长的进行优化）
     */
    @RequiresPermissions("monitor:time:edit")
    @Log(title = "系统响应时间统计记录（方便对响应时间长的进行优化）", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysCostTime sysCostTime)
    {
        return toAjax(sysCostTimeService.updateSysCostTime(sysCostTime));
    }

    /**
     * 删除系统响应时间统计记录（方便对响应时间长的进行优化）
     */
    @RequiresPermissions("monitor:time:remove")
    @Log(title = "系统响应时间统计记录（方便对响应时间长的进行优化）", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysCostTimeService.deleteSysCostTimeByIds(ids));
    }
}
